<?php
namespace Admin\Controller;

use Admin\Model\UserModel;
use Common\Model\ImageModel;
use Think\Controller;
use Admin\Model\DoctorsModel;
use Common\Model\HuanxinLogic;

class UserController extends Controller {

    protected $instance = NULL;

    public function __construct() {
        parent::__construct();
        if ($this->instance == NULL) {
            $user = new UserModel();
            $this->instance=$user->where(['status'=>0]);
        }
    }

    public function index() {
        $count = $this->instance->count();
        $Page = new \Think\Page($count, 20);
        $Page->setConfig('theme', "<ul class='pagination'></li><li>%FIRST%</li><li>%UP_PAGE%</li><li>%LINK_PAGE%</li><li>%DOWN_PAGE%</li><li>%END%</li><li><span> %HEADER%  %NOW_PAGE%/%TOTAL_PAGE% 页 </span></li></ul>");
        $Pageshow = $Page->show();
        $index = [
            "limit" => array(
                "firstRow" => $Page->firstRow,
                "listRows" => $Page->listRows,
            ),
        ];
        $user = $this->instance->index($index);
        $this->assign('user', $user);
        $this->assign('Pageshow', $Pageshow);
        $this->display();
    }

    public function auditUser() {
        $data['id'] = I('get.id');
        $data['status'] = 1;
        $userObj = M('user_car');
        if ($userObj->create($data, 2)) {
            $status = $userObj->save();
            if ($status) {
                return $this->success('审核成功', U('Admin/User/index'));
            } else {
                return $this->success('审核失败', U('Admin/User/index', ['id' => $data['id']]));
            }
        } else {
            return $this->success('审核失败', U('Admin/User/index', ['id' => $data['id']]));
        }

    }


    public function test(){

//        $image = new ImageModel();
//        $image=$image->uploadImage($user_id,$_FILES);
//        $this->ajaxReturn(['status'=>1,'image'=>$image]);
//        var_dump($image);
//        exit;
//        if ($userObj->create($data, 1)) {
//            $status = $userObj->add();
//        }

        return $this->display();
    }

    public function postTest(){
        $user_id= I('post.patient_id');


        $image = new ImageModel();
        $image=$image->uploadImage($user_id,$_FILES['image']);

        $this->ajaxReturn(['status'=>1,'image'=>$image]);
//        var_dump($image);
//        exit;
//        if ($userObj->create($data, 1)) {
//            $status = $userObj->add();
//        }
//        var_dump($user_id,$_FILES);
    }

}